package uk.ac.ebi.dod.beans;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
 * @author Florian Reisinger
 * @since x0.1
 */
public class Enzyme {

    private static final Log log = LogFactory.getLog(Enzyme.class);

    private int type;
    private String name;
    private String cleavePattern;
    private String restrictors;
    private int misCleavages;
    private boolean cterm;

    // for IN-TABLE-ROW-DELETION
    private List<Enzyme> parent;

    ///// ///// ///// ///// /////
    // CONSTRUCTOR

    public Enzyme() {
        log.debug("Creating new Enzyme.");
    }

    public Enzyme(int type, String name, String cleave, String restict, int misCleavages, boolean cterm) {
        this.type = type;
        this.name = name;
        this.cleavePattern = cleave;
        this.restrictors = restict;
        this.misCleavages = misCleavages;
        this.cterm = cterm;
    }

    public Enzyme(String name, String cleave, String restict, boolean cterm) {
        this.name = name;
        this.cleavePattern = cleave;
        this.restrictors = restict;
        this.cterm = cterm;
    }

    ///// ///// ///// ///// /////
    // METHODS

    public String action() {
        if (parent != null) {
            parent.remove(this);
            log.debug("Removed enzyme [" + name + "] from list: " + parent);
        } else {
            log.error("Attempt to delete enzyme '" + this.getName() + "' from non-existing parent list: " + parent);
        }
        return null;
    }

    public String getCNTermAsString() {
        return cterm ? "Cterm" : "Nterm";
    }

    ///// ///// ///// ///// /////
    // GETTER & SETTER

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCleavePattern() {
        return cleavePattern;
    }

    public void setCleavePattern(String cleavePattern) {
        this.cleavePattern = cleavePattern;
    }

    public String getRestrictors() {
        return restrictors;
    }

    public void setRestrictors(String restrictors) {
        this.restrictors = restrictors;
    }

    public int getMisCleavages() {
        return misCleavages;
    }

    public void setMisCleavages(int misCleavages) {
        this.misCleavages = misCleavages;
    }

    public boolean isCterm() {
        return cterm;
    }

    public void setCterm(boolean cterm) {
        this.cterm = cterm;
    }

    public List<Enzyme> getParent() {
        return parent;
    }

    public void setParent(List<Enzyme> parent) {
        this.parent = parent;
    }
}
